home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Mania 5
/
MacMania 5.toast
/
/
Internet software
/
NewsWatcher
/
NW Source
/
Source
/
status.c
< prev
next >
Wrap
Text File
|
1997-01-09
|
9KB
|
352 lines
/*----------------------------------------------------------------------------
status.c
This module handles the status window.
Copyright © 1994-1997, Northwestern University.
----------------------------------------------------------------------------*/
#include <string.h>
#include "glob.h"
#include "status.h"
#include "newswatcher.h"
#include "dialog.h"
#include "menus.h"
#include "strutil.h"
#include "windutil.h"
#include "memutil.h"
#include "wind.h"
#include "help.h"
#define kWindowWidth 450 /* status window width */
#define kWindowHeight 80 /* status window height */
static Str255 gStatusMsg; /* currently displayed status message */
/*----------------------------------------------------------------------------
DisplayStatusMessage
Display a status message during a long operation.
Entry: msg = status message.
Exit: function result = error code.
----------------------------------------------------------------------------*/
OSErr DisplayStatusMessage (char *msg)
{
WindowPtr wind = nil;
GrafPtr port;
Rect r;
Str255 title, buttonName, fontName;
OSErr err = noErr;
Boolean mainScreen, onOneScreen;
GetPort(&port);
wind = MyFrontWindow();
strcpy((char*)gStatusMsg, msg);
c2pstr((char*)gStatusMsg);
if (GetMyWindowKind(wind) != kStatus) {
GetPString(kStrStatusWindowTitle, title);
GetFontName(systemFont, fontName);
err = CreateNewWindow(kStatus, title, fontName, 12, &wind);
if (err != noErr) goto exit;
MoveWindow(wind, gPrefs.statusWindowLocn.h, gPrefs.statusWindowLocn.v, false);
SizeWindow(wind, kWindowWidth, kWindowHeight, false);
if (!WindOnScreen(wind)) {
GetDominantScreen(nil, &r, &mainScreen, &onOneScreen);
MoveWindow(wind, (r.left + r.right - wind->portRect.right) >> 1,
GetMBarHeight() + 40, false);
}
SetRect(&r, kWindowWidth-70, kWindowHeight-30, kWindowWidth-10, kWindowHeight-10);
GetPString(kStrStatusCancelButtonName, buttonName);
NewControl(wind, &r, buttonName, true, 0, 0, 0, pushButProc, 0);
MyShowWindow(wind);
} else {
SetPort(wind);
SetRect(&r, 10, 10, kWindowWidth-10, 40);
InvalRect(&r);
}
SetMenusTo(kAppleOnlyAboutDisabled, 0, 0, 0, 0, 0);
GiveTime(false);
SetPort(port);
return noErr;
exit:
DoClose(wind);
SetPort(port);
return err;
}
/*----------------------------------------------------------------------------
DisplayStatusMessageNumber
Display a status message during a long operation.
Entry: index = index in STR# 128 resource of status message.
Exit: function result = error code.
----------------------------------------------------------------------------*/
OSErr DisplayStatusMessageNumber (short index)
{
CStr255 msg;
GetCString(index, msg);
return DisplayStatusMessage(msg);
}
/*----------------------------------------------------------------------------
Activate
Handle an activate event for the status window.
Entry: wind = pointer to status window.
act = true to activate, false to deactivate
----------------------------------------------------------------------------*/
static void Activate (WindowPtr wind, Boolean act)
{
}
/*----------------------------------------------------------------------------
Update
Handle an update event for the status window.
Entry: wind = pointer to status window.
----------------------------------------------------------------------------*/
static void Update (WindowPtr wind)
{
UpdateControls(wind, wind->visRgn);
TextFont(systemFont);
TextSize(12);
TruncString(kWindowWidth-20, gStatusMsg, smTruncEnd);
MoveTo(10, 29);
DrawString(gStatusMsg);
#ifdef kDevelopmentVersion
{
char *t1 = "NewsWatcher development version.";
char *t2 = "Please do not redistribute.";
TextFont(applFont);
TextSize(9);
MoveTo(10, 60);
DrawText(t1, 0, strlen(t1));
MoveTo(10, 71);
DrawText(t2, 0, strlen(t2));
}
#endif
}
/*----------------------------------------------------------------------------
Mouse
Handle a mouse down event in the content area of the status window.
Entry: wind = pointer to status window.
where = location of mouse down in local coords.
modifiers = modifiers field from event record.
Exit: function result = error code.
----------------------------------------------------------------------------*/
static OSErr Mouse (WindowPtr wind, Point where, short modifiers)
{
short part;
ControlHandle control;
part = FindControl(where, wind, &control);
if (part != 0) {
if (TrackControl(control, where, nil) != 0) gCancel = true;
}
return noErr;
}
/*----------------------------------------------------------------------------
Draggable
Determine whether a mouse down event is on a draggable object in a
status window.
Entry: wind = pointer to status window.
where = location of mouse down event, in local coordinates.
modifiers = modifiers field from event record.
Exit: function result = true if object is draggable.
----------------------------------------------------------------------------*/
static Boolean Draggable (WindowPtr wind, Point where, short modifiers)
{
return false;
}
/*----------------------------------------------------------------------------
Key
Handle a key down event for the status window.
Entry: wind = pointer to status window.
theChar = ASCII code of key.
theKey = keyboard code of key.
modifiers = modifiers field from event record.
Exit: function result = error code.
----------------------------------------------------------------------------*/
static OSErr Key (WindowPtr wind, unsigned char theChar, unsigned char theKey, short modifiers)
{
ControlHandle cancelButton;
long ticks;
if (theKey == escapeKeyCode || (modifiers & cmdKey) != 0 && theChar == '.') {
cancelButton = ((WindowPeek)wind)->controlList;
HiliteControl(cancelButton, 1);
Delay(8, &ticks);
HiliteControl(cancelButton, 0);
gCancel = true;
return noErr;
}
SysBeep(0);
return noErr;
}
/*----------------------------------------------------------------------------
Command
Handle a command for the status window.
Entry: wind = pointer to status window.
menu = the menu.
item = the item.
modifiers = modifiers field from event record.
Exit: function result = error code.
----------------------------------------------------------------------------*/
static OSErr Command (WindowPtr wind, short menu, short item, short modifiers)
{
return noErr;
}
/*----------------------------------------------------------------------------
Close
Close the status window.
Entry: wind = pointer to status window.
Exit: function result = error code.
----------------------------------------------------------------------------*/
static OSErr Close (WindowPtr wind)
{
TWindow **info;
GrafPtr port;
GetPort(&port);
SetPort(wind);
SetPt(&gPrefs.statusWindowLocn, 0, 0);
LocalToGlobal(&gPrefs.statusWindowLocn);
info = (TWindow**)GetWRefCon(wind);
MyDisposeHandle(info);
MyDisposeWindow(wind);
SetPort(port);
return noErr;
}
/*----------------------------------------------------------------------------
Idle
Handle idle time tasks for a status window.
Entry: wind = pointer to status window.
Exit: cursorRgn = cursor region for WaitNextEvent mouse moved events.
----------------------------------------------------------------------------*/
static void Idle (WindowPtr wind, RgnHandle cursorRgn)
{
}
/*----------------------------------------------------------------------------
Help
Handle help balloons for a status window.
Entry: wind = pointer to status window.
where = current mouse location in local coordinates.
----------------------------------------------------------------------------*/
static void Help (WindowPtr wind, Point where)
{
Rect r;
Point tip = {0,0};
SetRect(&r, wind->portRect.right-70, wind->portRect.bottom-30,
wind->portRect.right-10, wind->portRect.bottom-10);
if (PtInRect(where, &r)) ShowHelpBalloon(tip, &r, 9);
}
/*----------------------------------------------------------------------------
InitStatusDispatchTable
Initialize the dispatch table for the status window.
----------------------------------------------------------------------------*/
void InitStatusDispatchTable (void)
{
TDispatch *d;
d = &gDispatch[kStatus];
d->activate = Activate;
d->update = Update;
d->mouse = Mouse;
d->draggable = Draggable;
d->key = Key;
d->grow = nil;
d->zoom = nil;
d->command = Command;
d->close = Close;
d->idle = Idle;
d->help = Help;
}